﻿using System;
using System.Collections.Generic;
using System.DAL;
using System.IBLL;
using System.IDAL;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System.BLL
{
    public class StaffManager : IStaffManager
    {
        public bool Login(string LoginName, string PassWord, bool IsManager, out string StaffId, out string DepId)
        {
            if (IsManager)
            {
                using (IStaffService userSvc = new StaffService())
                {
                    var data = userSvc.GetAllAsync().FirstOrDefault(m => m.StaffName == LoginName && m.PassWord == PassWord);
                    if (data != null)
                    {
                        StaffId = data.Id.ToString();
                        DepId = data.DepartmentRoleId.ToString();
                        return true;
                    }
                    else
                    {
                        StaffId = "未查询到";
                        DepId = "未查询到";
                        return false;
                    }
                }
            }
            else
            {
                using (IHouseholdService userSvc = new HouseholdService())
                {

                    var data = userSvc.GetAllAsync().FirstOrDefault(m => m.UserName == LoginName && m.PassWord == PassWord);
                    if (data != null)
                    {
                        StaffId = data.Id.ToString();
                        DepId = data.DepartmentRoleId.ToString();
                        return true;
                    }
                    else
                    {
                        StaffId = "未查询到";
                        DepId = "未查询到";
                        return false;
                    }
                }
            }
  
        }
    }
}
